/*
 * Copyright 2008 Jens Meiss
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.hmvc4gwt.example.hmvcblog.service.gwtrpc.client.blog.entry.comment;

import com.google.gwt.core.client.GWT;
import com.googlecode.hmvc4gwt.example.hmvcblog.service.dto.blog.entry.comment.BlogEntryCommentNewDTO;
import com.googlecode.hmvc4gwt.example.hmvcblog.service.dto.blog.entry.comment.BlogEntryCommentRemoveDTO;
import com.googlecode.hmvc4gwt.example.hmvcblog.service.gwtrpc.client.blog.entry.comment.events.out.BlogEntryCommentSuccessfullAddedEvent;
import com.googlecode.hmvc4gwt.example.hmvcblog.service.gwtrpc.client.blog.entry.comment.events.out.BlogEntryCommentSuccessfullRemovedEvent;
import com.googlecode.hmvc4gwt.framework.client.rpc.AAsyncCallback;
import com.googlecode.hmvc4java.event.IEvent;
import com.googlecode.hmvc4java.event.IEventListener;

/**
 * 
 * @author jens.meiss
 */
public class BlogEntryCommentAsyncCallback<T, E extends IEvent> extends AAsyncCallback<T, E> {

	private static IBlogEntryCommentRemoteServiceAsync remoteService;

	/**
	 * @param remoteService the remoteService to set
	 */
	public static void setRemoteService(
			IBlogEntryCommentRemoteServiceAsync remoteService) {
		BlogEntryCommentAsyncCallback.remoteService = remoteService;
	}

	/**
	 * @return the remoteService
	 */
	public static IBlogEntryCommentRemoteServiceAsync getRemoteService() {
		
		if (remoteService == null) {
			setRemoteService((IBlogEntryCommentRemoteServiceAsync) GWT.create(IBlogEntryCommentRemoteService.class));
		}
		
		return remoteService;
	}
	
	public static void addBlogEntryComment(BlogEntryCommentNewDTO blogEntryCommentNewDTO, IEventListener eventListener) {
	
		BlogEntryCommentAsyncCallback<Void, BlogEntryCommentSuccessfullAddedEvent> callback = new BlogEntryCommentAsyncCallback<Void, BlogEntryCommentSuccessfullAddedEvent>();
		callback.setEventListener(eventListener);
		callback.setEventOnSuccess(new BlogEntryCommentSuccessfullAddedEvent());
		
		getRemoteService().addBlogEntryComment(blogEntryCommentNewDTO, callback);
		
	}
	
	public static void removeBlogEntryComment(BlogEntryCommentRemoveDTO blogEntryCommentRemoveDTO, IEventListener eventListener) {
		
		BlogEntryCommentAsyncCallback<Void, BlogEntryCommentSuccessfullRemovedEvent> callback = new BlogEntryCommentAsyncCallback<Void, BlogEntryCommentSuccessfullRemovedEvent>();
		callback.setEventListener(eventListener);
		callback.setEventOnSuccess(new BlogEntryCommentSuccessfullRemovedEvent());
		
		getRemoteService().removeBlogEntryComment(blogEntryCommentRemoveDTO, callback);
		
		
	}
}
